package com.info.zhiduoduo.admin.model.formbean.project;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.info.zhiduoduo.common.constants.Constants;
import com.info.zhiduoduo.common.constants.company.CompanyPayType;
import com.info.zhiduoduo.common.constants.project.CompanyProjectState;
import com.info.zhiduoduo.common.excelconverter.AutoCheckConverter;
import com.info.zhiduoduo.common.excelconverter.InvoiceTypeConverter;

import com.info.zhiduoduo.common.validator.ExcelDecimalValid;
import com.info.zhiduoduo.common.validator.ExcelValid;
import com.info.zhiduoduo.repository.entity.company.CompanyProject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ImportZddProjectTemplateFormBean {

	//序号
	@ExcelProperty(index = 0)
	private Integer row;
	//企业名称
	@ExcelProperty(index = 1)
	@ExcelValid(message = "企业名称不能为空")
	private String companyName;
	//项目名称
	@ExcelProperty(index = 2)
	@ExcelValid(message = "项目名称不能为空")
	private String projectName;
	//项目描述
	@ExcelProperty(index = 3)
	@ExcelValid(message = "项目描述不能为空")
	private String projectDesc;
	//项目周期
	@ExcelProperty(index = 4)
	private int projectcycle;
	//项目成交金额
	@ExcelProperty(index = 5)
	@ExcelValid(message = "项目金额不能为空")
	@ExcelDecimalValid(min = "0", max = "50000", message = "交易金额错误")
	private Double projectAmount;
	//项目服务费
	@ExcelProperty(index = 6)
	private Double projectservicecharge;
	//项目税金
	@ExcelProperty(index = 7)
	private Double projecttaxfee;
	//项目支付给创客的金额
	@ExcelProperty(index = 8)
	private Double projectPayAmount;
	//项目税率
	@ExcelProperty(index = 9)
	private Double projectTaxRate;
	//项目基础服务费率
	@ExcelProperty(index = 10)
	private Double projectBaseServiceRate;
	//项目分类
	@ExcelProperty(index = 11)
	private String category;
	//发票类型
	@ExcelProperty(index = 12, converter = InvoiceTypeConverter.class)
	private Integer invoiceType;
	//发票内容
	@ExcelProperty(index = 13)
	@ExcelValid(message = "发票内容不能为空")
	private String invoiceContent;
	//自动验收
	@ExcelProperty(index = 14, converter = AutoCheckConverter.class)
	private Integer authCheck;
	//姓名
	@ExcelProperty(index = 15)
	private String name;
	//银行卡号
	@ExcelProperty(index = 16)
	private String acctno;
	//身份证号
	@ExcelProperty(index = 17)
	@ExcelValid(message = "身份证号不能为空")
	private String idno;
	//创建日期
	@ExcelProperty(index = 18)
	private Date createtime;
	//完成时间
	@ExcelProperty(index = 19)
	private Date finishtime;
	//项目开始时间
	@ExcelProperty(index = 20)
	private Date projectstart;

	//解析后新增数据
	@ExcelIgnore
	private Integer compid;
	@ExcelIgnore
	private Integer partyId;
	@ExcelIgnore
	private Integer userId;
	@ExcelIgnore
	private String realname;
	//工作室名称
	@ExcelIgnore
	private String username;
	//项目分类ID,默认0
	@ExcelIgnore
	private int categoryId;

	public CompanyProject toEntity(ImportZddProjectTemplateFormBean bean) {
		return new CompanyProject().setProjectcycle(bean.getProjectcycle())
								   .setCompid(bean.getCompid())
								   .setCompname(bean.getCompanyName())
								   .setProjectname(bean.getProjectName())
								   .setUserid(bean.getUserId())
								   .setRealname(bean.getRealname())
								   .setUsername(bean.getUsername())
								   .setCategoryid(bean.getCategoryId())
								   .setProjectintro(bean.getProjectDesc())
								   .setInvoicetype(bean.getInvoiceType())
								   .setInvoicecontent(bean.getInvoiceContent())
								   .setProjectamount(BigDecimal.valueOf(bean.getProjectAmount()))
								   .setProjectdealamount(BigDecimal.valueOf(bean.getProjectAmount()))
								   .setProjectservicecharge(BigDecimal.valueOf(bean.getProjectservicecharge()))
								   .setProjecttaxfee(BigDecimal.valueOf(bean.getProjecttaxfee()))
								   .setProjectPayAmount(BigDecimal.valueOf(bean.getProjectPayAmount()))
								   .setProjectTaxRate(bean.getProjectTaxRate())
								   .setProjectBaseServiceRate(bean.getProjectBaseServiceRate())
								   .setProjectPartnerServiceRate(0d)
								   .setProjectsubmit(new Date())
								   .setProjectstart(bean.getProjectstart())
								   .setProjectfinish(bean.getFinishtime())
								   .setProjectcheckstart(bean.getFinishtime())
								   .setProjectcheckend(bean.getFinishtime())
								   .setOfflinePayTime(new Date())
								   .setOfflinePayState(Constants.OFFLINE_PAID)
								   .setState(CompanyProjectState.COMPLETED)
								   .setCreatetime(bean.getCreatetime())
								   .setSupplementTime(new Date())
								   .setWhetherSupplement(1)
								   .setPartyId(bean.getPartyId());
	}
}